package com.ra.pojo;

import com.ra.enums.StatusCodeEnum;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.ra.enums.StatusCodeEnum.*;
/**
 * Author : 今晚几点睡_Ada
 * Date: 2023/3/9
 * Time: 10:43
 * 注:通用返回结果对象
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RespBean<T>{
    private long code;

    private String message;

    private T obj;

    private static <T> RespBean<T> RespBean(Integer code, String message, T obj) {
        return RespBean.<T>builder()
                .code(code)
                .message(message)
                .obj(obj).build();
    }

    /**
     * 成功返回结果
     * @param <T>
     * @return
     */
    public static <T> RespBean<T> success() {
        return RespBean(SUCCESS.getCode(), SUCCESS.getDesc(),null);
    }

    public static <T> RespBean<T> success(String message) {
        return RespBean(SUCCESS.getCode(), message,null);
    }
    public static <T> RespBean<T> success(T obj) {
        return RespBean(SUCCESS.getCode(), SUCCESS.getDesc(),obj);
    }
    /**
     * 失败返回结果
     *
     * @param
     */
  //  public static <T> RespBean<T> error() {
    //    return RespBean(ERROR.getCode(), ERROR.getDesc(),null);
   // }
   // public static <T> RespBean<T> error(Integer code,String message) {
    //    return RespBean(code, message,null);
   // }
    public static <T> RespBean<T> error(StatusCodeEnum statusCodeEnum) {
        return RespBean(statusCodeEnum.getCode(), statusCodeEnum.getDesc(),null);
    }
    public static <T> RespBean<T> error(T obj) {
        return RespBean(ERROR.getCode(), ERROR.getDesc(),obj);
    }




}
